﻿using System;
using System.Linq;
using System.Data.Linq;
using DR.DBDomainModel;
using DR.Repository.Abstract;

namespace DR.Repository.Concrete.LinqToSql
{
    public class LinqToSqlDeveloperRepository : LinqToSqlBaseRepository<Developer, int>, IDeveloperRepository
    {
        public LinqToSqlDeveloperRepository(string connectionString) : base(connectionString)
        {            
        }

        protected override Table<Developer> GetDataTable(DataContext dataContext)
        {
            return dataContext.GetTable<Developer>();
        }

        protected override System.Linq.Expressions.Expression<Func<Developer, bool>> GetIDQuery(int id)
        {
            return r => r.DeveloperID == id;
        }

        protected override int GetEntityID(Developer entity)
        {
            return entity.DeveloperID;
        }

        public Developer SelectDeveloperByUserID(Guid userID)
        {
            using (DataContext dc = CreateDataContext())
            {
                return dc.GetTable<Developer>().FirstOrDefault(r => r.aspnet_UsersID == userID);
            }
        }
    }
}
